package data.deployed;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import configuration.Paths;

import main.Core;

/**
 * A script that generates the default database and properties that exist upon
 * first installation.
 * 
 * @author Richard
 */
public class DeployedDataSetupScript {

	public static void main(String[] args) {
		// Start framework core
		Core.getInstance().startup();

		// Save default inventory properties
		Properties defaultWorkspaceProps = new Properties();
		defaultWorkspaceProps.setProperty("maximized", "false");
		Properties inventoryProps = new Properties(defaultWorkspaceProps);
		try {
			File defaultWorkspacePropsFile = new File(Paths.propertiesPath
					+ File.separator
					+ "default_workspace.properties");
			if (!defaultWorkspacePropsFile.exists()) {
				defaultWorkspacePropsFile.createNewFile();
			}
			FileOutputStream fos = new FileOutputStream(defaultWorkspacePropsFile);
			defaultWorkspaceProps.store(fos,
					"Deployed default workspace properties.");
			File workspacePropsFile = new File(Paths.propertiesPath
					+ File.separator
					+ "workspace.properties");
			if (!workspacePropsFile.exists()) {
				workspacePropsFile.createNewFile();
			}
			fos = new FileOutputStream(workspacePropsFile);
			inventoryProps.store(fos,
					"Deployed workspace properties.");
			fos.close();
		} catch (FileNotFoundException e) {
			Core.getInstance().logMessage(
					DeployedDataSetupScript.class.getName(),
					"The workspace properties file could not be found.", e);
		} catch (IOException e) {
			Core.getInstance().logMessage(
					DeployedDataSetupScript.class.getName(),
					"Error writing deployed workspace properties file.", e);
		}

		// Generate Character Sprites
		// CharacterSprite jackSprite = new CharacterSprite("Jack",
		// "[[NO BODY]]",
		// "[[NO HEAD]]", "[[NO HAIR]]", "[[NO DRESS]]", "[[NO FACE]]");
		// CharacterSpriteDatabase.getInstance().addNewSprite(jackSprite);

		// Generate Character Points
		// CharacterPoint goldPoint = new CharacterPoint("Gold", 0, 999999, 0);
		// CharacterPoint xpPoint = new CharacterPoint("Experience", 0, 999999,
		// 0);
		// CharacterPoint levelPoint = new CharacterPoint("Level", 0, 999, 1);
		// CharacterPoint hpPoint = new CharacterPoint("HP", 0, 9999, 100);
		// CharacterPoint mpPoint = new CharacterPoint("MP", 0, 9999, 100);
		// CharacterPoint strengthPoint = new CharacterPoint("Strength", 0, 999,
		// 10);
		// CharacterPoint agiltyPoint = new CharacterPoint("Agilty", 0, 999,
		// 10);
		// CharacterPoint magicPoint = new CharacterPoint("Magic", 0, 999, 10);
		// CharacterPoint physicalDefensePoint = new CharacterPoint(
		// "Physical Defense", 0, 999, 10);
		// CharacterPoint magicalDefensePoint = new CharacterPoint(
		// "Magical Defense", 0, 999, 10);
		// CharacterPointDatabase.getInstance().addNewPoint(goldPoint);
		// CharacterPointDatabase.getInstance().addNewPoint(xpPoint);
		// CharacterPointDatabase.getInstance().addNewPoint(levelPoint);
		// CharacterPointDatabase.getInstance().addNewPoint(hpPoint);
		// CharacterPointDatabase.getInstance().addNewPoint(mpPoint);
		// CharacterPointDatabase.getInstance().addNewPoint(strengthPoint);
		// CharacterPointDatabase.getInstance().addNewPoint(agiltyPoint);
		// CharacterPointDatabase.getInstance().addNewPoint(magicPoint);
		// CharacterPointDatabase.getInstance().addNewPoint(physicalDefensePoint);
		// CharacterPointDatabase.getInstance().addNewPoint(magicalDefensePoint);

		// Shutdown core (saves databases)
		Core.getInstance().shutdown();
	}

}
